package com.topscore.uke.mvp.model;

import com.topscore.uke.entities.PerformanceData;
import com.topscore.uke.mvp.contractors.GetTeamPerformanceContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/10/20.
 */

public class GetTeamPerformanceModel implements GetTeamPerformanceContractor, GetTeamPerformanceContractor.Model {
    private CallBack mCallBack;
    private String mGroupCode;

    public GetTeamPerformanceModel(String groupCode) {
        this.mGroupCode = groupCode;
    }

    @Override
    public void getPerformanceInMonth(String month) {
        mService.getTeamPerformanceInMonth(month, mGroupCode)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<PerformanceData>>(mCallBack) {
                    @Override
                    public void onSuccess(BaseResponse<PerformanceData> response) {
                        mCallBack.onGetDataSuccess(response);
                    }
                });
    }

    @Override
    public void getPerformanceInYear(String year) {
        mService.getTeamPerformanceInYear(year, mGroupCode)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<PerformanceData>>(mCallBack) {
                    @Override
                    public void onSuccess(BaseResponse<PerformanceData> response) {
                        mCallBack.onGetDataSuccess(response);
                    }
                });
    }

    @Override
    public Model setCallBack(CallBack callBack) {
        this.mCallBack = callBack;
        return this;
    }
}
